package com.ruoyi.system.mq;

import com.ruoyi.system.domain.notificationResult.OrderNotification;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.util.List;

/**
 * createOrderConsumer
 * 缴费提醒--消息生产者
 * @author life.
 * @date 2025/4/5
 */
@Component
@RocketMQMessageListener(topic = "create-money-order", consumerGroup = "create-smart-order")
public class createOrderConsumer implements RocketMQListener<List<OrderNotification>> {
    private static final Logger logger = LoggerFactory.getLogger(createOrderConsumer.class);

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public void onMessage(List<OrderNotification> orderNotification) {
        try {
            /*
            * 缴费消息生产者
            * */
            GenericMessage<List<OrderNotification>> listGenericMessage = new GenericMessage<>(orderNotification);
            // 发送消息，并添加发送结果回调
            rocketMQTemplate.asyncSend("cancel-money-order", listGenericMessage, new SendCallback() {
                @Override
                public void onSuccess(SendResult sendResult) {
                    logger.info("消息发送成功，消息内容: {}, 发送结果: {}", listGenericMessage, sendResult);
                }

                @Override
                public void onException(Throwable e) {
                    logger.error("消息发送失败，消息内容: {}", listGenericMessage, e);
                }
            });
            logger.info("接收到的消息: {}", listGenericMessage);
        } catch (Exception e) {

        }
    }


}